package com.stdu;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.stdu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class JsonController {
    @ResponseBody
    @RequestMapping("/testJson")
    public String jsonTest() throws JsonProcessingException {

        User user=new User();
        user.setId(33);
        user.setUsername("202303");
        user.setPassword("030303");
        ObjectMapper json=new ObjectMapper();
        List<User> list=new ArrayList<>();


        User user1=new User();
        user1.setId(333);
        user.setUsername("admin333");
        user.setPassword("pwd333");
        list.add(user);
        list.add(user1);
        return json.writeValueAsString(user);
    }
}
